// 使用useReducer 模仿一个增加删除的效果
import React, { useReducer } from 'react'

const StudyUseReducer = () => {
  const [num, setNum] = useReducer((state, action) => {
    switch (action) {
      case 'add':
        return state + 1

      case 'jian':
        return state - 1
      default:
        break
    }
  }, 0)

  const handlerAdd = () => {
    setNum('add')
  }
  const handlerJian = () => {
    setNum('jian')
  }

  return (
    <div>
      <button onClick={handlerJian}>-</button>
      <div>{num}</div>
      <button onClick={handlerAdd}>+</button>
      <div className="iconfont  icon-shoujihaochaxun"></div>
    </div>
  )
}

export default StudyUseReducer
